package traitement;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import com.mxgraph.util.mxResources;

public class ProgressDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	private JProgressBar progressBar;
	private JLabel label;
	private JPanel centerPanel;
	private int progress = 0;
	
	public JProgressBar getProgressBar() {
		return progressBar;
	}

	public void setProgressBar(JProgressBar progressBar) {
		this.progressBar = progressBar;
	}
	
	public ProgressDialog(JFrame jframe){
		super(jframe, mxResources.get("processingRunning"));
		progressBar = new JProgressBar(0,100);
		progressBar.setValue(0);
		//progressBar.setIndeterminate(true);
		
		label = new JLabel(mxResources.get("processingRunning"));
		
		centerPanel = new JPanel();
		
		centerPanel.add(label);
		centerPanel.add(progressBar);
		
		this.getContentPane().add(centerPanel, BorderLayout.CENTER);
		
		this.setLocationRelativeTo(null);
		this.setPreferredSize(new Dimension(220, 100));
		this.pack();
		//this.setVisible(true);
	}
	
	public JLabel getLabel() {
		return label;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}
	
	public void setTaskRunning(String task){
		this.label.setText(task);
	}
	
	public static void main(String[] args){
		ProgressDialog p = new ProgressDialog(null);
		p.setVisible(true);
	}
	
	public void setProgress(int p){
		//progress += p;
		progressBar.setValue(p);
	}
	
	public void reset(){
		progress=0;
		progressBar.setValue(progress);
	}
}
